home *** CD-ROM | disk | FTP | other *** search
- class Rescuer extends MovieClip
- {
- var score_readable;
- var direction;
- var life;
- var glevel;
- var char_name;
- var invincible;
- var jump_is_available;
- var is_available;
- var move_speed;
- var ESCALATE_SPEED;
- var accel;
- var movement;
- var BACKGROUND_WIDTH;
- var WIDTH_BOUNDS;
- var Char;
- var lastHitFollower;
- var follower;
- var ground;
- var currentPowerItem;
- var last_escalator;
- var interval_id;
- var Wheeler;
- var Trike;
- var Guitar;
- var SkateBoard;
- var STAGE_WIDTH = 700;
- var STAGE_HEIGHT = 450;
- var JUMP_SPEED = 4.8;
- var DEFAULT_SPEED = 5;
- var GRAVITY = 0.9;
- var ACCEL_ACCEL = 0.2;
- var HEIGHT_MINUS = 16;
- function Rescuer()
- {
- super();
- this._name = "Rescuer";
- _global[this._name] = this;
- this.score_readable = 0;
- this.direction = 0;
- this.life = 1;
- this.glevel = 1;
- this.char_name = _global.char_selected;
- this.gotoAndStop(this.char_name);
- this.resetGround();
- this.invincible = false;
- this.jump_is_available = true;
- this.is_available = true;
- this.move_speed = this.DEFAULT_SPEED;
- this.ESCALATE_SPEED = this.DEFAULT_SPEED / 2;
- this.accel = 0;
- this.movement = [];
- this.accel = 0;
- this.BACKGROUND_WIDTH = _global.MallCrawl._width;
- this.WIDTH_BOUNDS = {left:this.STAGE_WIDTH / 3 + this._width,right:this.STAGE_WIDTH - this.STAGE_WIDTH / 3 - this._width};
- _global.DebugWindow.watchRescuer();
- }
- function onEnterFrame()
- {
- if(this.is_available && !_global.MallCrawl.paused)
- {
- if(Key.isDown(32))
- {
- if(this.jump_is_available)
- {
- this.jump();
- }
- }
- if(Key.isDown(38))
- {
- if(this.hitTest(_global.MallCrawl.Background.Exit))
- {
- if(!_global.MallCrawl.twinsArray.length)
- {
- _global.MallCrawl.winLevel();
- }
- }
- var _loc3_ = 0;
- while(_loc3_ < _global.MallCrawl.upEscalators.length)
- {
- if(this.hitTest(_global.MallCrawl.upEscalators[_loc3_].HitSquare))
- {
- this.rideEscalator(_global.MallCrawl.upEscalators[_loc3_],"up");
- }
- _loc3_ = _loc3_ + 1;
- }
- }
- if(Key.isDown(40))
- {
- _loc3_ = 0;
- while(_loc3_ < _global.MallCrawl.downEscalators.length)
- {
- if(this.hitTest(_global.MallCrawl.downEscalators[_loc3_].HitSquare))
- {
- this.rideEscalator(_global.MallCrawl.downEscalators[_loc3_],"down");
- }
- _loc3_ = _loc3_ + 1;
- }
- }
- if(Key.isDown(39) || Key.isDown(37))
- {
- this.Char.gotoAndStop("walk");
- if(Key.isDown(39))
- {
- this.moveRight();
- }
- if(Key.isDown(37))
- {
- this.moveLeft();
- }
- }
- else
- {
- this.Char.gotoAndStop("still");
- this.direction = 0;
- }
- _loc3_ = 0;
- while(_loc3_ < _global.MallCrawl.twinsArray.length)
- {
- if(this.hitTest(_global.MallCrawl.twinsArray[_loc3_]) && _global.MallCrawl.twinsArray[_loc3_].is_available)
- {
- this.score_readable += _global.Twins.twin_points;
- this.lastHitFollower = _global.MallCrawl.twinsArray[_loc3_];
- if(this.followerCheck(this) != _global.MallCrawl.twinsArray[_loc3_])
- {
- _global.Footer.addScore(500);
- if(this.follower)
- {
- var _loc4_ = this.followerCheck(this.follower);
- _loc4_.fillMovement();
- _loc4_.addFollower(_global.MallCrawl.twinsArray[_loc3_]);
- }
- else
- {
- this.fillMovement();
- this.addFollower(_global.MallCrawl.twinsArray[_loc3_]);
- _global.MallCrawl.twinsArray[_loc3_].onEnterFrame = undefined;
- }
- }
- }
- _loc3_ = _loc3_ + 1;
- }
- }
- if(this.is_available)
- {
- this._y += this.GRAVITY + this.accel;
- if(this._y + this.accel >= this.ground)
- {
- this._y = this.ground;
- this.jump_is_available = true;
- this.accel = 0;
- }
- else
- {
- this.jump_is_available = false;
- this.accel += this.ACCEL_ACCEL;
- }
- }
- if(this.follower)
- {
- this.movement.push({x:this._x,y:this._y - this.HEIGHT_MINUS,scale:this._xscale,moving:this.Char._currentframe > 1});
- if(this.movement.length > _global.MallCrawl.FOLLOWER_DISTANCE)
- {
- this.follower.twinMovement(this.movement.popFirst());
- }
- }
- }
- function loseFollower()
- {
- this._parent.attachMovie("Damage","Damage",this._parent.getNextHighestDepth(),{_x:this._x,_y:this._y});
- var _loc2_ = this.followerCheck(this);
- if(_loc2_ != this)
- {
- _loc2_.runAway(this.leaderCheck(this,this.followerCheck(this.follower)));
- }
- else
- {
- this.loseLife();
- }
- }
- function loseLife()
- {
- _global.Footer.setLives(_global.Footer.lives - 1);
- if(!_global.Footer.lives)
- {
- _global.MallCrawl.gameOver();
- }
- }
- function fillMovement()
- {
- var _loc3_ = 0;
- while(_loc3_ < _global.MallCrawl.FOLLOWER_DISTANCE)
- {
- this.movement.push({x:this._x,y:this._y - this.HEIGHT_MINUS,scale:this._xscale,moving:this.Char._currentframe > 1});
- if(this.movement.length > _global.MallCrawl.FOLLOWER_DISTANCE)
- {
- this.follower.twinMovement(this.movement.popFirst());
- }
- _loc3_ = _loc3_ + 1;
- }
- this.follower.fillMovement();
- }
- function fadeAlpha(amt)
- {
- this._alpha = amt;
- this.follower.fadeAlpha(this._alpha);
- this.fillMovement();
- return this._alpha;
- }
- function escalate(escalator)
- {
- if(escalator.direction < 0)
- {
- if(this._y + this._height - this.HEIGHT_MINUS > escalator._y)
- {
- this.invincible = true;
- this.moveRight(this.ESCALATE_SPEED);
- this._y -= this.ESCALATE_SPEED;
- }
- else
- {
- if(!this.currentPowerItem)
- {
- this.invincible = false;
- }
- this.is_available = true;
- this.last_escalator = undefined;
- this.resetGround();
- clearInterval(this.interval_id);
- }
- }
- else if(this._y + this._height < escalator._y + escalator._height + this.HEIGHT_MINUS)
- {
- this.invincible = true;
- this.moveRight(this.ESCALATE_SPEED);
- this._y += this.ESCALATE_SPEED;
- }
- else
- {
- if(!this.currentPowerItem)
- {
- this.invincible = false;
- }
- this.is_available = true;
- this.last_escalator = undefined;
- this.resetGround();
- clearInterval(this.interval_id);
- }
- }
- function followerCheck(mc)
- {
- if(mc.follower)
- {
- return this.followerCheck(mc.follower);
- }
- return mc;
- }
- function leaderCheck(mc, name)
- {
- if(mc.follower == name)
- {
- return mc;
- }
- if(mc.follower)
- {
- return this.leaderCheck(mc.follower,name);
- }
- return false;
- }
- function addFollower(mc)
- {
- mc.onEnterFrame = undefined;
- mc.gotoAndStop("walk");
- _global.MallCrawl.tcounterArray.push(mc);
- this.follower = _global.MallCrawl.twinsArray.popByName(mc);
- this.follower.movement = new Array();
- }
- function resetGround()
- {
- this.ground = _global.MallCrawl["GLevel" + this.glevel]._y - this._height + this.HEIGHT_MINUS;
- this._y = this.ground;
- }
- function jump()
- {
- this.jump_is_available = false;
- this.accel = -1 * this.JUMP_SPEED;
- this._y = this.ground - 1;
- }
- function rideEscalator(escalator, type)
- {
- this._x = escalator._x;
- if(type == "up")
- {
- if(this._y > escalator._y && this.last_escalator != escalator)
- {
- this.is_available = false;
- this.last_escalator = escalator;
- escalator.activate(this);
- }
- }
- else if(type == "down")
- {
- if(this._y < escalator._y - 5 && this.last_escalator != escalator)
- {
- this.is_available = false;
- this.last_escalator = escalator;
- escalator.activate(this);
- }
- }
- }
- function moveLeft(speed)
- {
- !!speed ? null : (speed = this.move_speed);
- this._xscale >= 0 ? null : (this._xscale *= -1);
- if(this._x > this._width)
- {
- this._x -= speed;
- }
- if(this._x + _global.MallCrawl._x < this.WIDTH_BOUNDS.left)
- {
- if(_global.MallCrawl._x < 0)
- {
- _global.MallCrawl._x += speed;
- }
- else
- {
- _global.MallCrawl._x = 0;
- }
- }
- }
- function moveRight(speed)
- {
- !!speed ? null : (speed = this.move_speed);
- this._xscale <= 0 ? null : (this._xscale *= -1);
- if(this._x < this.BACKGROUND_WIDTH - this._width)
- {
- this._x += speed;
- }
- if(this._x + _global.MallCrawl._x > this.WIDTH_BOUNDS.right)
- {
- if(_global.MallCrawl._x > - (this.BACKGROUND_WIDTH - this.STAGE_WIDTH))
- {
- _global.MallCrawl._x -= speed;
- }
- else
- {
- _global.MallCrawl._x = - (this.BACKGROUND_WIDTH - this.STAGE_WIDTH);
- }
- }
- }
- function resetPowerItems()
- {
- this.Wheeler.gotoAndStop("stop");
- this.Trike.gotoAndStop("stop");
- this.Guitar.gotoAndStop("stop");
- this.SkateBoard.gotoAndStop("stop");
- }
- }
-